<template>
  <el-container class="my-layout">
    <el-aside width="200px">
      <img src="@/assets/image/logo.png" alt="">
      <el-menu :default-active="$route.path" background-color="#223344" text-color="#fff" router>
        <el-menu-item index="/">
          <i class="el-icon-s-home"></i>
          <span slot="title">数据概览</span>
        </el-menu-item>
        <el-menu-item index="/article">
          <i class="el-icon-document"></i>
          <span slot="title">内容管理</span>
        </el-menu-item>
        <el-menu-item index="/publish">
          <i class="el-icon-s-promotion"></i>
          <span slot="title">发布文章</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <img :src="user.photo" id="avatar" alt="">
        <span>{{ user.name || user.mobile }}</span>
        <el-link :underline="false" icon="el-icon-unlock" @click="onlayout">退出</el-link>
      </el-header>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import auth from '@/utils/token'

export default {
  name: 'LayoutView',
  data () {
    return {
      user: {}
    }
  },
  methods: {
    onlayout () {
      this.$confirm('确定要退出登陆吗?', '提示', {
        confirmButtonText: '爽快退出',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        auth.delToken()
        this.$message.success('退出成功')
        this.$router.push('/login')
      }).catch(() => {})
    }
  },
  async created () {
    const res = await this.$http.get('/v1_0/user/profile')
    this.user = res.data.data
    // console.log(res)
  }
}
</script>

<style scoped>
.my-layout {
  height: 100vh;
  display: flex;
  justify-content: center;

  .el-menu {
    border-right: none;
  }

  .el-header {
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: end;
    align-items: center;
    gap: 15px;

    #avatar {
      width: 30px;
      height: 30px;
      border-radius: 30px;
    }
  }

  img {
    width: 80%;
  }
}

.el-aside {
  background-color: #223344;
  height: 100vh;
}
</style>
